package com.md.youyouhui.utils;

import android.app.Dialog;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.md.youyouhui.R;
import com.md.youyouhui.databinding.DialogAdapterMealBinding;
import com.md.youyouhui.ui.adapter.DataBoundViewHolder;

import java.util.List;

/**
 * Created by AdministratorZJ
 * on 2019/4/29.
 */
public class MealMinuteDialog extends Dialog {
    private Context context;
    private List<String> month, time;
    private String money;

    public MealMinuteDialog(Context context, List<String> month, List<String> time, String money) {
        super(context);
        this.context = context;
        this.month = month;
        this.money = money;
        this.time = time;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_meal);
        RecyclerView recyclerView = findViewById(R.id.dialogRecycler);
        recyclerView.setAdapter(new MyAdapter());
    }

    class MyAdapter extends RecyclerView.Adapter<DataBoundViewHolder<DialogAdapterMealBinding>> {

        @NonNull
        @Override
        public DataBoundViewHolder<DialogAdapterMealBinding> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            DialogAdapterMealBinding mealBinding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.dialog_adapter_meal, viewGroup, false);
            return new DataBoundViewHolder<>(mealBinding);
        }

        @Override
        public void onBindViewHolder(@NonNull DataBoundViewHolder<DialogAdapterMealBinding> holder, int i) {
            holder.binding.money.setText(money);
            holder.binding.num.setText(month.get(i));
            holder.binding.time.setText(time.get(i));
        }

        @Override
        public int getItemCount() {
            return null == month ? 0 : month.size();
        }
    }
}
